package com.xbrother.vo;

import lombok.Data;

/**
 * 响应
 *
 * @author huangchangjin
 * @date 2025/4/25 16:10
 */
@Data
public class R<T> {
    /**
     * 编码
     */
    private String code;
    /**
     * 消息
     */
    private String msg;
    /**
     * 数据
     */
    private T data;

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.setCode("200");
        r.setMsg("操作成功");
        r.setData(data);
        return r;
    }

    public static <T> R<T> success() {
        return success(null);
    }

    public static <T> R<T> error(String code, String msg) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }

    public static <T> R<T> error(String msg) {
        return error("500", msg);
    }

    public static <T> R<T> error() {
        return error("error");
    }
}
